﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Twodi.Interfaces;
using Twodi.Aspect.Interfaces;
using Microsoft.Xna.Framework;
using Twodi.Aspect.Args;

namespace Twodi.Aspect.Implemented
{
    /// <summary>
    /// Define um componente que possui escala.
    /// </summary>
    public class ScaleAspect : DependentAspect<IScaleAspect>, IScale
    {
        /// <summary>
        /// Escala do componente.
        /// </summary>
        private float scale = 1f;

        /// <summary>
        /// Construtor padrão.
        /// </summary>
        public ScaleAspect(IScaleAspect component)
            : base(component)
        {
            ScaleChanged += (sender, e) =>
            {
                DefaultChangedEventArgs<float> args = e as DefaultChangedEventArgs<float>;
                this.Component.SizeProperties.Size = Vector2.Multiply(this.Component.SizeProperties.Size, args.ActualValue / args.PreviousValue);
            };
        }

        /// <summary>
        /// Escala do componente.
        /// </summary>
        public float Scale
        {
            get
            {
                return this.scale;
            }
            set
            {
                OnPropertyChanged<float>("Scale", ref scale, value);
            }
        }

        /// <summary>
        /// Evento invocado quando escala é alterada.
        /// </summary>
        public event EventHandler ScaleChanged;

        /// <summary>
        /// Método invocado no momento que a escala é alterada.
        /// </summary>
        /// <param name="e"></param>
        protected virtual void onScaleChanged(EventArgs e)
        {
            if (ScaleChanged != null) ScaleChanged(this, e);
        }
    }
}
